﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZS_MessageViewControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        CustomGridView CustomGridList1;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            if (!base.Page.IsPostBack)
            {
                Bind();
            }
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
        }
        protected void Bind()
        {
            CustomGridList1.RowDataBound += new GridViewRowEventHandler(CustomGridList1_RowDataBound);
            DataTable dt = _EluZSDataProvider.GetZNMessage(GetSqlWhere());
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.PageSize = 10;
            CustomGridList1.DataKeyNames = new string[] { "ID" };
            CustomGridList1.DataBind();
        }
        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }
        protected void CustomGridList1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView rowview = (DataRowView)e.Row.DataItem;
                string strISREAD = rowview["ISREAD"].ToString();
                if (!string.IsNullOrEmpty(strISREAD))
                {
                    if (strISREAD == "0")
                    {
                        e.Row.Cells[4].Text = "未读";
                        e.Row.Cells[4].Attributes.Add("style", "color:Red;");
                    }
                    else if (strISREAD == "1")
                    {
                        e.Row.Cells[4].Text = "已读";
                        e.Row.Cells[4].Attributes.Add("style", "color:blue;");
                    }
                }
            }
        }
        protected string GetSqlWhere() {
            string sqlWhere = string.Empty;
            string luid = string.Empty;
            if (base.Page.Session["UserID"] != null)
            {
                luid = base.Page.Session["UserID"].ToString();
            }
            if (!string.IsNullOrEmpty(luid))
            {
                sqlWhere = " and receiveuserid  = '" + luid + "'";
            }
            return sqlWhere;
        }
    }
}


